﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

//using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows;
using System.Media;
using Coding4Fun.Kinect.Wpf.Controls;
using System.Windows.Media;
using com.skype.api;
using Hugo.UIOptions;

namespace Hugo.UIPages
{
    public class SkypeContactListUI : SlidingTileUIPage
    {

        public enum SkypeAction { Call, Message };

        SkypeAction action;
        bool contactsUpdated = false;

        private List<SkypeMessageUIOption> messageOptions = new List<SkypeMessageUIOption>();

        public SkypeContactListUI(String name, BitmapSource iconSource, SkypeAction a)
            : base(name, iconSource)
        {
            this.action = a;
        }

        public override string getDescription()
        {
            if (action == SkypeAction.Call)
            {
                return "Who to call?";
            }
            else
            {
                return "Who to message?";
            }
        }
       

        public void addMessageOptions(List<SkypeMessageUIOption> options)
        {
            this.messageOptions = options;
        }

        public override void setPage()
        {
            updateSkypeList();
            base.setPage();
        }

        private void updateSkypeList()
        {
            contactsUpdated = false;

            if (!contactsUpdated)
            {
                clearPage();

                Contact[] contacts = Communicate.getInstance().getContacts();

                contactsUpdated = true;

                if (contacts == null) { return; }

                foreach (Contact c in contacts)
                {
                    if (!c.getDisplayName().Contains("Echo"))
                    {
                        if (action == SkypeAction.Call)
                        {
                            this.addUIOption(new SkypeCallUIOption(c.getDisplayName(), c.getDisplayName(), Util.getImageForContact(c)));
                        }
                        else if (action == SkypeAction.Message)
                        {
                            this.addUIOption(new SkypeMessageListUI(c.getDisplayName(), messageOptions, Util.getImageForContact(c)));
                        }
                    }
                }
            }
            
        }
    }
}
